package com.sdehua.wear.controller;

import com.sdehua.wear.entity.Address;
import com.sdehua.wear.service.AddressService;
import com.sdehua.wear.utils.ResultEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * (Address)表控制层
 *
 * @author makejava
 * @since 2022-01-01 22:47:07
 */
@RestController
@RequestMapping("address")
@CrossOrigin
public class AddressController {
    /**
     * 服务对象
     */
    @Resource
    private AddressService addressService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Address selectOne(Integer id) {
        return this.addressService.queryById(id);
    }

    @RequestMapping("queryOne")
    public ResultEntity queryOne(String userId){
        List<Address> addresses = addressService.queryOneByUserId(userId);
        if (addresses == null || addresses.size()<1){
            return ResultEntity.fail("查询失败");
        }
        return  ResultEntity.success(addresses);
    }

    @RequestMapping("addAddress")
    public ResultEntity addAddress(String userId,String def,String address,String phone){
        boolean flag = addressService.addAddress(userId,def,address,phone);
        return ResultEntity.success("开发中...");
    }

}